#导入langchain的tool
from langchain.agents import tool
from pydantic_model.tool_order_detail_query_model import SearchInput
from model.local_deep_seek_r1 import DeepSeekR1Prompt

# from mysqlExecutor import MysqlExecutor

query_detail_sql = r"""
select a.phone                                                                '号码',
       a.sms_content                                                          '内容',
       su.user_name                                                           '客户名称',
       sg.gateway_name                                                        '网关名称',
       a.gmt_create                                                           '提单时间',
       a.complete_time                                                        '接收时间',
       a.delivered_part                                                       '条数',
       case a.status when 100 then '成功' when -1 then '失败' else '其他' end '状态',
       a.memo                                                                 '备注'
from sms_order_202502 a
left join sms_gateway sg on a.gateway_id = sg.id
left join sms_user su on a.user_id = su.id
left join sms_product_info spi on a.product_id = spi.id
where 
  a.gateway_id in (2974)
  and b.user_id in (2974)
  and a.gmt_create >= "2025-02-22 00:00:00"
  and a.gmt_create <= "2025-02-24 23:59:59"
  and a.status = 100
;
"""

#添加tool装饰器
@tool(args_schema=SearchInput)
def search(args: SearchInput) -> str:
    """通过条件查询订单明细"""
    # 打印进入日志
    print(f"进入{__name__}，参数：{args}")
    ds = DeepSeekR1Prompt()
    sql = ds.answer("根据参数：{args_schema}, 修改{query_detail_sql}中的参数， 给出完整的查询语句。请直接给出sql语句。")

    for token in sql:
        print(token)
    return "42f"